package pe.edu.upc.dreamteam.service.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.springframework.beans.factory.annotation.Autowired;

import pe.edu.upc.dreamteam.bean.Reserva;
import pe.edu.upc.dreamteam.dao.ReservaDAO;

public class ReservasListener implements MessageListener {

	@Autowired
	ReservaDAO reservaDAO;
	
	@Override
	public void onMessage(Message message) {
		if (message instanceof ObjectMessage) {
			final ObjectMessage objectMessage = (ObjectMessage) message;
			try {
				Reserva reserva = (Reserva)objectMessage.getObject();
				reservaDAO.registrarReserva(reserva);
			} catch (final JMSException e) {
				e.printStackTrace();
			}
		}
	}

}
